var walluid;
var countWall;
var intervalIdWall;

function initWallIndex() {
    var delay = 5000;
    
    updateWall();
    intervalIdWall = setInterval(updateWall, delay);
}

// ini dipanggil waktu user nge update wall-wallnya
function updateWall() {
    var walls = getElementByClass("wall", document.getElementById("allWallToShow"));
    var newestWall = walls[0];

    var newestWallId;
    if (newestWall) {
        newestWallId = newestWall.id.replace("wall-", "");
    }

    var ajax = new AjaxWrap();
    ajax.onLoadSuccess = function(ajax) {
        var allWallToShow =document.getElementById("allWallToShow");
        allWallToShow.innerHTML = ajax.xhr.responseText + allWallToShow.innerHTML;
    }

    var param = "";
    if (newestWall) {
        param = newestWallId;
    }
    
    ajax.openAndSend("POST", URL_BASE + "wall/newestWall/" + param + "?uid=" + walluid, true, "ajax=true");
}

// ini dipanggil waktu user nge klik tombol more wall
function moreWall(uid) {
    window.event.preventDefault();
    var walls = getElementByClass("wall", document.getElementById("allWallToShow"));
    var oldestWall = walls[walls.length - 1];
    var oldestWallId = oldestWall.id.replace("wall-", "");

    var ajax = new AjaxWrap();
    ajax.onLoadSuccess = function(ajax) {
        document.getElementById("allWallToShow").innerHTML += ajax.xhr.responseText;
    }
    
    ajax.openAndSend("POST", URL_BASE + "wall/index/" + oldestWallId + "?uid=" + uid, true, "ajax=true&partial=true");
    return false;
}

function moreWallComment(wallid) {
    window.event.preventDefault();

    var ajax = new AjaxWrap();
    ajax.onLoadSuccess = function(ajax) {
        document.getElementById("allWallCommentToShow-" + wallid).innerHTML += ajax.xhr.responseText;
    }

    ajax.openAndSend("POST", URL_BASE + "wall/getWallComment/" + wallid + "?uid=" + uid, true, "ajax=true&partial=true");

    return false;
}

function closeWallIndex() {
    // Stop
    if(intervalIdWall) {
        clearInterval(intervalIdWall);
    }
}